package com.qf.shopping.controll;

import com.qf.shopping.dto.systemDTO.UserProfileDTO;
import com.qf.shopping.pojo.System.User;
import com.qf.shopping.service.AdminMangerService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/person")
@SessionAttributes("user")
public class PersonControll {

    @Autowired
    private AdminMangerService adminMangerService=null;
    @GetMapping("/person")
    public String getUser(Model model, HttpSession session){
        User s= (User) session.getAttribute("suser");
        UserProfileDTO user=adminMangerService.findUserById(s.getId());
        model.addAttribute("user",user);
        return "/person/info";
    }

    @PutMapping ("/updateperson")
    public String update(UserProfileDTO user ){
        adminMangerService.updateUser(user);
        return "redirect:/person/person";
    }

    @GetMapping("/repassword/{id}")
    public String torepassword(@PathVariable("id") Integer id, Model model){
        UserProfileDTO u=adminMangerService.findUserById(id);
        model.addAttribute("repassword",u.getPassword());
        return "/person/repassword";
    }

    @PostMapping("/repassword")
    public String repassword(Integer id,String password){

        return "redirect:/person/person";
    }
}
